<?php
namespace Admin\Controller;
use Think\Controller;
class ConfigController extends CommonController {
	public function index(){
		//实例化对象
		$config = M('config');
		$id = 1;
		//执行查询
		$list_config = $config -> where('id='.$id) -> select();
		//分配变量
		$a = $this -> assign('list_config',$list_config);
		// dump($a);die;
		$this->display();
	}

	//系统参数修改
	public function edit(){
		//判断
		if(IS_POST){
			$rules = array(
				array('name','require','*网站名称为必填项'),//默认情况下用正则进行验证
				array('url','require','*URL为必填项或者URL格式不正确'),
				array('title','require','*网站标题为必填项'),
				array('keywords','require','*网站关键字为必填项'),
				array('copyright','require','*网站版权信息为必填项'),
				array('telephone','require','*联系电话为必填项'),
				array('address','require','*联系地址为必填项'),
				array('template','require','*模板选择为必填项'),
				array('is_moble','require','*是否开启手机站为必填项'),
				//array('e_address','','*发送邮箱为必填项或者邮箱格式不正确'),
				array('e_name','require','*发件人姓名为必填项'),
				array('e_SMTP','require','*SMTP为必填项'),
				array('e_port','require','*邮箱端口号为必填项'),
				//array('e_username','require|email','*邮箱为必填项或者格式不正确'),
				array('e_password','require','*邮箱密码为必填项'),
				array('thumbsize','require','*上传图片尺寸为必填项'),
				array('is_water','require','*是否添加水印为必填项'),
				array('is_close','require','*是否关闭网站为必填项'),
				);
			//实例化对象
			$config = M('config');
			if(!$config -> validate($rules) -> create()){
				//如果创建失败，表单验证失败，输出错误信息
				alertMes($config -> getError());
			}else{
				$id = 1;
				$arr = $config -> create();
				$arr['e_password'] = md5($arr['e_password']);
				//执行修改
				$res = $config -> where('id='.$id) -> save($arr);
				if($res){
					alertMes('系统配置成功','/admin/config/index');
				}else{
					alertMes('系统配置失败','/admin/config/index');
				}
			}

		}else{
			alertMes('系统配置失败','/admin/config/index');
		}
	}

}